<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');

if (reqVar('azione') == 'elimina') {
	$msgPag .= confElim();
} 
if (reqVar('azione') == 'gencod') {
	$msgPag .= rigeneraCodice();
} 
$sqlSel = "SELECT * FROM rgl_mod_rque " .
		" WHERE id_mod_rque = ".intval(reqVar('id'));
$objDB->query($sqlSel,'selRec');
if (!$acRec = $objDB->fetch('selRec')) {
	backOnErr("var. id. '".reqVar('id')."' mancante o errato");
}
$_REQUEST = array_merge($acRec,$_REQUEST);

$sSql = "SELECT s.*  FROM rgl_mod_rque_sez s WHERE id_mod_rque = ".reqVar('id')
	." ORDER BY s.seq, s.cod_sez_rque ";
$objDB->query($sSql,'sezRque');

$cmdL = "";
$cmdL .= "&nbsp;&nbsp;&nbsp;";
$cmdL .= "<a class='cmd1' href='modRqueVis.php?id=".reqVar('id')."&$sXSNQS' >punteggi</a>";

$sCmdPagR = '';
if (true) {
	$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
	$sCmdPagR .= "<a class='cmd1' href='sezRqueIns.php?id=".reqVar('id')."&$sXSNQS' >nuova sezione</a>";
}
$sCmdPagR .= cmdTorna(); 

testaHtml('Gestione modelli',$msgPag, 'modl');
?>
<script language="JavaScript" type="text/javascript">
  	function confElim() {
  		if (confirm("Confermi l'eliminazione del modello ?")) {
  			document.location.href = "<?=$_SERVER['PHP_SELF']."?id=".reqVar('id')."&azione=elimina&".$sXSNQS?>";
  		}
  	}
</script>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif(20);?>
   <tr>
	   <td class="cmd1" align="left" colspan='10'><?=$cmdL?></td>
	   <td class="cmd1" align="right" colspan='10'><?=$sCmdPagR?></td>
   </tr>
   <tr>
      <td class="tit1" colspan='20' align='center'>Modello rating a questionario</td>
   </tr>
<?
$aCamForm = array();
require("_inc/const.campiModRque.php");
// non visualizza script vuoto
if (reqVarTrim('nota')=='') {
	foreach($aCamForm as $rr => $aX) {
		foreach($aX as $cc => $aY) {
			if ($aY[0]=='nota') {
				unset($aCamForm[$rr][$cc]);
			}
		}
	}
}
echo getHtmlCampiForm($aCamForm,'vis');
?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Sezioni</td>
   </tr>
   <tr>
      <td class="lab1" colspan='1' align='center'>Seq</td>
      <td class="lab1" colspan='2' align='center'>Codice</td>
      <td class="lab1" colspan='16' align='center'>Descrizione</td>
      <td class="lab1" colspan='1' align='center'>Peso</td>
   </tr>
<?
while($aSez=$objDB->fetch('sezRque')) {
?>
   <tr>
      <td class="txt1" colspan='1' align='right' valign='top'>
      	<a class='txt1' href='sezRqueVis.php?id=<?=$aSez['id_sez_rque']?>&xsn=<?=XSN?>'>
      		<?=$aSez['seq']?></a>&nbsp;
      <td class="txt1" colspan='2' align='left' valign='top'>
      	<a class='txt1' href='sezRqueVis.php?id=<?=$aSez['id_sez_rque']?>&xsn=<?=XSN?>'>
      		<?=$aSez['cod_sez_rque']?></a>
      </td>
      <td class="txt1" colspan='16' align='left' valign='top'><?=$aSez['descr']?></td>
      <td class="txt1" colspan='1' align='right' valign='top'><?=$aSez['peso']?>&nbsp;</td>
   </tr>
<?
}
?>
	<tr>
	   <td class="cmd1" align="left" colspan='10'><?=$cmdL?></td>
	   <td class="cmd1" align="right" colspan='10'><?=$sCmdPagR?></td>
	</tr>
</table>

<?
codaHtml();
exit();

function confElim() {
	global $objDB;
	//return "TODO";
	$msg = '';
	$sSqlDel = "SELECT * FROM rgl_mod_rglob WHERE id_mod_rque = ".intval(reqvar('id'));
	$objDB->exec($sSqlDel);
	if ($acX=$objDB->fetch()) {
		$msg .= "modello utilizzato da mod.glob '".$acX['cod_mod_rglob']."'<br>";
	}
	if ($msg != '') {
		return $msg;
	}

	//$sSqlDel = "DELETE FROM rgl_mod_rque_par_ind WHERE id_mod_rque = ".intval(reqvar('id'));
	//$objDB->exec($sSqlDel);
	$sSqlDel = "DELETE FROM rgl_puntque WHERE id_mod_rque = ".intval(reqvar('id'));
	$objDB->exec($sSqlDel);
	$sSqlDel = "DELETE FROM rgl_mod_rque WHERE id_mod_rque = ".intval(reqvar('id'));
	$objDB->exec($sSqlDel);
	//return "<pre>".print_r($objDB,1)."</pre>";
	header("Location: ".urlTorna());
	exit();
}
